use std::borrow::Cow;

use thiserror::Error;

pub type IoErr = std::io::Error;
pub type SqlxErr = sqlx::Error;

#[derive(Debug, Error)]
pub enum AppErr {

    #[error("io:{0}")]
    Io(#[from] IoErr),

    #[error("sqlx:{0}")]
    Sqlx(#[from] SqlxErr),

    #[error("{0}")]
    Custom(Cow<'static, str>),

    #[error("cbor:{0}")]
    Cbor(#[from] serde_cbor::Error),
}

pub fn new_err_static(msg: &'static str) -> AppErr {
    AppErr::Custom(Cow::Borrowed(msg))
}

pub fn new_err(msg: String) -> AppErr {
    AppErr::Custom(Cow::Owned(msg))
}

